package com.whfc.ms.api.base.controller;

import com.whfc.base.dto.SceneDTO;
import com.whfc.common.base.BaseController;
import com.whfc.common.result.Result;
import com.whfc.common.result.ResultUtil;
import com.whfc.common.util.SessionAttr;
import com.whfc.entity.dto.UploadImgDTO;
import com.whfc.fuum.entity.SysUser;
import com.whfc.ms.api.base.service.MsAppSceneService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @ClasssName AppSceneController
 * @Description 现场模拟
 * @Author hw
 * @Date 2021/3/25 16:01
 * @Version 1.0
 */
@RestController
@RequestMapping("/ms/api/scene")
public class AppSceneController extends BaseController {

    @Autowired
    private MsAppSceneService msAppSceneService;


    @RequiresPermissions("prj/sence/edit")
    @PostMapping("/add")
    public Result add(@SessionAttribute(SessionAttr.MS_USER) SysUser user,
                      @RequestBody @Validated SceneDTO param) {
        logger.info("现场模拟-添加，loginer:{},param:{}", user.getUsername(), param);
        msAppSceneService.add(param);
        return ResultUtil.success();
    }


    @RequiresPermissions("prj/sence/edit")
    @PostMapping("/edit")
    public Result edit(@SessionAttribute(SessionAttr.MS_USER) SysUser user,
                       @RequestBody @Validated SceneDTO param) {
        logger.info("现场模拟-修改，loginer:{},param:{}", user.getUsername(), param);
        msAppSceneService.edit(param);
        return ResultUtil.success();
    }

    @RequiresPermissions("prj/sence/edit")
    @PostMapping("/del/{id}")
    public Result del(@SessionAttribute(SessionAttr.MS_USER) SysUser user, @PathVariable("id") Integer id) {
        logger.info("现场模拟-删除，loginer:{},param:{}", user.getUsername(), id);
        msAppSceneService.del(id);
        return ResultUtil.success();
    }

    @GetMapping("/details")
    public Result details(@SessionAttribute(SessionAttr.MS_USER) SysUser user,
                          @RequestParam("deptId") Integer deptId) {
        logger.info("现场模拟详情，loginer:{},deptId:{}", user.getUsername(), deptId);
        SceneDTO data = msAppSceneService.details(deptId);
        return ResultUtil.success(data);
    }

    @RequiresPermissions("prj/sence/imgUpload")
    @PostMapping("/uploadImg")
    public Result uploadImg(@SessionAttribute(SessionAttr.MS_USER) SysUser user, MultipartFile file) {
        logger.info("现场模拟上传图片，loginer:{}", user.getUsername());
        UploadImgDTO uploadImgDTO = msAppSceneService.uploadImg(file);
        return ResultUtil.success(uploadImgDTO);
    }
}
